-- OddAltar
-- Created by chengb Feb/3/2016
-- 奇怪的祭坛格子

require "game/ui/form/dungeon/special/UIOddAltar"

-- 初始化
function initOddAltar(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 祭坛激活中
            if self.gridData.activing then
                cclog("祭坛激活中。");
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 打开奇怪的祭坛界面
            local uiForm = UIOddAltar.create(self.gridData);
            UIMgr.getCurrentScene():removeFormByName("UIOddAltar");
            UIMgr.getCurrentScene():addForm(uiForm);

            -- 音效
            AudioM.playFx("ui_open1");
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
end

-- 奇怪的祭坛激活的事件
function onOddAtarActive(self)
    local function callback()
        -- 执行奖励
        local pos = self.gridData:getPos();
        DungeonActionM.go("do_building_bonus", pos);
    end
    -- 锁屏
    wait(2.5);
    -- 播放祭坛激活的光效
    playOddAltarActiveEffect(self, callback);
end
